from pybloom_live import BloomFilter

import constant.whiteList
from constant.whiteList import get_white_list


async def create_list(version_bid: str, length: int):
    bf = BloomFilter(length)
    for w in range(length):
        bf.add("HUAWEI-MATE-PRO-" + str(w))
    if bf is None or bf.__len__ == 0:
        return False
    await constant.whiteList.put_white_list(version_bid, bf)
    return True


async def id_in_whitelist(version: str, id: str):
    whitel = await get_white_list(version)
    if whitel is None or whitel.__len__ == 0:
        return False
    if id in whitel:
        return True
    return False
